#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i ++) cin >> a[i];
  vector<int> sum(n + 1);
  partial_sum(a.begin(), a.end(), sum.begin());
  vector<vector<int>> dp(n + 1, vector<int>(n + 1));
  int ans = 0;
  for (int l = n; l >= 1; l --) {
    dp[l][l] = 1;
    ans = max(ans, a[l]);
    for (int r = l + 1; r <= n; r ++) {
      int rr = r;
      int ll = l;
      while (ll < rr) {
        if (sum[ll] - sum[l - 1] == sum[r] - sum[rr - 1]) {
          if (dp[l][ll] && dp[rr][r] && (dp[ll + 1][rr - 1] || ll + 1 == rr)) {
            dp[l][r] = 1;
            break;
          }
          ll ++, rr--;
        } else if (sum[ll] - sum[l - 1] < sum[r] - sum[rr - 1]) ll ++;
        else rr --;
      }
      if (dp[l][r]) ans = max(ans, sum[r] - sum[l - 1]);
    }
  }
  cout << ans << endl;
}